package org.example.physics_engine.geometry.shapes;

import lombok.Getter;
import lombok.Setter;
import org.example.physics_engine.body.Transform;
import org.example.physics_engine.geometry.Vector2d;

@Getter
@Setter
public class Rectangle extends Polygon{

    //矩形的半宽
    protected double halfWidth;
    //矩形的半高
    protected double halfHeight;

    public Rectangle(double halfWidth, double halfHeight, Transform transform, Vector2d[] vertices) {
        super(transform, vertices, new Vector2d[]{
                new Vector2d(0.0, -1.0),
                new Vector2d(1.0, 0.0),
                new Vector2d(0.0, 1.0),
                new Vector2d(-1.0, 0.0)
        });
        this.halfWidth = halfWidth;
        this.halfHeight = halfHeight;
    }

    public Rectangle(double halfWidth, double halfHeight, Transform transform) {
        this(halfWidth, halfHeight, transform, new Vector2d[]{
                new Vector2d(-halfWidth, -halfHeight),
                new Vector2d(halfWidth, -halfHeight),
                new Vector2d(halfWidth, halfHeight),
                new Vector2d(-halfWidth, halfHeight)
        });
    }

    public Rectangle(double halfWidth, double halfHeight) {
        this(halfWidth, halfHeight, new Transform());
    }

    //反序列化调用
    @Deprecated
    public Rectangle() {
        this(0.0, 0.0);
    }

    @Override
    public void zoom(int rate) {
        super.zoom(rate);
        if (rate < 1) return;
        this.halfWidth = this.halfWidth / this.rate * rate;
        this.halfHeight = this.halfHeight / this.rate * rate;
        this.rate = rate;
    }
}
